package com.ox.head.okex.common.sign;

import io.netty.handler.codec.http.HttpMethod;

import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

/**
 * @author even
 * @date 2021/5/14 0014 下午 13:32
 * @describe
 */
public class OkSignUtil {

    /**
     * get请求签名
     * @param timestamp
     * @param requestPath
     * @param queryString
     * @return
     * @ahtor even
     * @since
     */
    public static String getSign(String timestamp,String requestPath,String queryString,String secret){
        String sign=null;
        try {
            sign = HmacSHA256Base64Utils.sign(timestamp, HttpMethod.GET.toString(), requestPath, queryString, null, secret);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (InvalidKeyException e) {
            e.printStackTrace();
        }
        return sign;
    }
    /**
     * POST 请求签名
     * @param timestamp
     * @param requestPath
     * @param body
     * @return
     * @ahtor even
     * @since
     */
   public static String postSign(String timestamp,String requestPath,String body,String secret){
        String sign=null;
        try {
            sign = HmacSHA256Base64Utils.sign(timestamp,  HttpMethod.POST.toString(), requestPath, null, body, secret);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (InvalidKeyException e) {
            e.printStackTrace();
        }
        return sign;
    }
}
